package com.example.mybaseapp.ui.mvi

import androidx.lifecycle.ViewModelProvider
import com.example.lib_base.BaseActivity
import com.example.lib_base.mvi.TaskIntent
import com.example.lib_base.mvi.TaskViewModel
import com.example.mybaseapp.databinding.ActivityMviTaskBinding

class MVITaskActivity : BaseActivity<ActivityMviTaskBinding>() {
    private lateinit var viewModel: TaskViewModel

    override fun onViewInit() {
        viewModel = ViewModelProvider(this).get(TaskViewModel::class.java)

        // 观察状态
        viewModel.state.observe(this, { tasks ->
            // 更新 UI
        })

        // 发送意图
        viewModel.handleIntent(TaskIntent.LoadTasks)
        viewModel.handleIntent(TaskIntent.AddTask("New Task"))
        viewModel.handleIntent(TaskIntent.UpdateTask(0, "Updated Task"))
        viewModel.handleIntent(TaskIntent.DeleteTask(0))
    }

}